<div class="main-content">
    <div class="section__content section__content--p20">
        <div class="container-fluid">
            <div class="row m-b-30">
                <div class="col-lg-12">
                    <div class="overview-wrap">
                        <h2 class="title-1">编辑栏目</h2>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-header">
                            <strong>编辑栏目</strong>
                        </div>
                        <div class="card-body">
                            <form class="form-horizontal" role="form" name="form" id="form" method="post"
                                  data-bv-feedbackicons-valid="glyphicon glyphicon-ok"
                                  data-bv-feedbackicons-invalid="glyphicon glyphicon-remove"
                                  data-bv-feedbackicons-validating="glyphicon glyphicon-refresh"
                                  action="index.php?r=admin/module/editmoduledo">
                                <?php
                                if($parentid == 0){
                                    ?>
                                    <input type="hidden" name="parentid" value="-1">
                                    <?php
                                }else{
                                    ?>
                                    <input type="hidden" name="parentid" value="<?php echo $parent['module_id']; ?>">
                                    <?php
                                }
                                ?>
                                <input type="hidden" name="id" value="<?php echo $id ?>"/>
                                <input type="hidden" name="module_id" value="<?php echo $module['module_id']==null?0:$module['module_id']; ?>" />
                                <input type="hidden" name="YII_CSRF_TOKEN" value="<?php echo Yii::app()->request->csrfToken; ?>"/>

                                <div class="form-group">
                                    <label class=" form-control-label">父类菜单</label>
                                    <?php
                                    if($parentid == 0){
                                        ?>
                                        <select class="form-control" disabled="disabled">
                                            <option>顶级菜单</option>
                                        </select>
                                        <?php
                                    }else{
                                        ?>
                                        <select class="form-control" disabled="disabled">
                                            <option><?php echo $parent['category']; ?></option>
                                        </select>
                                        <?php
                                    }
                                    ?>
                                </div>

                                <div class="form-group">
                                    <label class=" form-control-label">模块名称</label>
                                    <input type="text" class="form-control" placeholder="模块名称" name="category"
                                           value="<?php echo $module['category']; ?>" data-bv-notempty="true"
                                           data-bv-notempty-message="模块名称是必须的！"/>
                                </div>

                                <div class="form-group">
                                    <label class=" form-control-label">排序</label>
                                    <input type="text" class="form-control" placeholder="排序" name="seq"
                                           value="<?php echo $module['seq']; ?>" data-bv-notempty="true"
                                           data-bv-notempty-message="排序是必须的！"/>
                                </div>

                                <div class="form-group">
                                    <label class=" form-control-label">打开方式</label>
                                    <select name="target" class="form-control">
                                        <?php
                                        if($module['target']=='_self'){
                                            ?>
                                            <option value="_self" selected="selected">当前页</option>
                                            <option value="_blank">新页面</option>
                                            <?php
                                        }else{
                                            ?>
                                            <option value="_self">当前页</option>
                                            <option value="_blank" selected="selected" >新页面</option>
                                            <?php
                                        }
                                        ?>
                                    </select>
                                </div>

                                <div class="form-group">
                                    <label class=" form-control-label">类别</label>
                                    <?php
                                    if($module!=null){
                                        ?>
                                        <?php echo $this->getModuleName($module['module']); ?>
                                        <input type="hidden" name="module" value="<?php echo $module['module']; ?>"/>
                                        <?php
                                    }else{
                                        ?>
                                        <select name="module" class="form-control"  onchange="showModuleTxt(this.value)">
                                            <option value='guide'>内容</option>
                                            <option value='article'>文章</option>
                                            <option value='product'>产品</option>
                                            <option value='download'>下载</option>
                                            <option value='image'>图片</option>
                                            <option value='job'>招聘</option>
                                            <option value='link'>链接</option>
                                        </select>
                                        <?php
                                    }
                                    ?>
                                </div>

                                <div class="form-group" id="link_txt" style="display: none;">
                                    <label class=" form-control-label">链接地址</label>
                                    <input type="text" class="form-control" placeholder="链接地址" name="url"
                                           value="<?php echo $module['url']; ?>" />
                                </div>

                                <div class="form-group" id="guide_txt">
                                    <label class=" form-control-label">内容</label>
                                    <textarea rows="3"
                                              name="content" style="height: 300px;width: 100%;"><?php echo $module['content']; ?></textarea>
                                </div>

                                <div class="form-group">
                                    <label class=" form-control-label">是否显示</label>
                                    <select class="form-control" name="ishid">
                                        <?php
                                        if($module['ishid']==0){
                                            ?>
                                            <option selected="selected" value="0">是</option>
                                            <option value="1">否</option>
                                            <?php
                                        }else{
                                            ?>
                                            <option value="0">是</option>
                                            <option value="1" selected="selected" >否</option>
                                            <?php
                                        }
                                        ?>

                                    </select>
                                </div>

                                <div class="form-group">
                                    <button  type="submit" name="submit" id="submit" class="btn btn-primary btn-lg btn-block">保存</button>
                                </div>

                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<link rel="stylesheet" href="/static/admin/lib/kindeditor/themes/default/default.css"/>
<script src="/static/admin/lib/kindeditor/kindeditor-min.js"></script>
<script charset="utf-8" src="/static/admin/lib/kindeditor/lang/zh_CN.js"></script>
<script>
    var editor = null;
    $(function(){
        initPage();
    });
    function initPage() {
        editor = initEdit("content", 'module')
        $('#form').bootstrapValidator();
        $('#form').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (formData, jqForm, options) {
                return $('#form').data('bootstrapValidator').isValid();
            },
            success: function (res) {
                if (message(res)) {
                    window.location.href = "index.php?r=admin/module/index";
                }
            }
        });
        // showModuleTxt($("select[name=module]").val());
    }
    function showModuleTxt(mv) {
        if(mv=='guide'){
            $("#guide_txt").show();
            $("#link_txt").hide();
        }else if(mv=='link'){
            $("#guide_txt").hide();
            $("#link_txt").show();
        }else{
            $("#guide_txt").hide();
            $("#link_txt").hide();
        }
    }
</script>